import * as proxy from '../proxy';
import ServiceBase from '../base';
import {UserModelProxy, UserResumesModelProxy} from '../proxies/user-model-proxy';
import {UserSecurityPageProxy} from '../proxies/user-security-page-proxy';
import {SimpleHttpRequestProxy} from '../proxies/simple-http-request-proxy';
import {UserPageProxy} from '../proxies/user-page-proxy';
// import ProjectListProxy from '../proxies/ProjectListProxy';
// import ProjectModelProxy from '../proxies/ProjectModelProxy';

const SAVE_USERINFO = '/users';

class UserService extends ServiceBase {
    // 获取用户信息 GET /users/username/{username}
    getUser = (data) => {
        let promise = super.get({
            url: SAVE_USERINFO + `/${data.username}`,
        });
        return proxy.httpResultProxy(promise, UserModelProxy);
    };
    // 获取用户的分页信息
    getUsersPaging = (data) => {
        let promise = super.get({
            url: `/users`,
            params: data,
        });
        return proxy.httpResultProxy(promise, UserPageProxy);
    };
    // 修改用户详细信息 PUT /users/{username}
    public saveUser = (data) => {
        const promise = super.put({
            url: SAVE_USERINFO + `/${data.username}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, UserModelProxy);
    };
    public setDefaultAccount = (data) => {
        const promise = super.put({
            url: SAVE_USERINFO + `/${data.userId}/preferences`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, UserModelProxy);
    };
    public shiftUserState = (data) => {
        const promise = super.put({
            url: `/users/${data.id}/state`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, UserModelProxy);
    };
    // 获取用户card信息 GET /users/card/{username}
    // getCard = (data) => {
    //   let promise = super.get(SAVE_USERINFO + `/card/${data.username}`);
    //   return proxy.httpResultProxy(promise);
    // };
    // save用户card信息 GET /users/card/{username}
    // putCard = (data) => {
    //   let promise = super.put(SAVE_USERINFO + `/card/${data.username}`, data.data);
    //   return proxy.httpResultProxy(promise);
    // };
    // 获取用户安全信息记录信息 GET /users/securityRecord
    getSecuritLog = (data) => {
        let promise = super.get({
            url: SAVE_USERINFO + `/securityRecord`,
            params: data,
        });
        return proxy.httpResultProxy(promise, UserSecurityPageProxy);
    };
    putUser = (data) => {
        let promise = super.put({
            url: SAVE_USERINFO,
            data,
        });
        return proxy.httpResultProxy(promise);
    };
    deleteUser = (data) => {
        let promise = super.delete({
            url: SAVE_USERINFO,
            params: data,
        });
        return proxy.httpResultProxy(promise);
    };

    // 注册用户
    postSignUpUser(data) {
        let promise = super.post({
            url: SAVE_USERINFO,
            data: data,
        });
        return proxy.httpResultProxy(promise, UserModelProxy);
    }
    postSignUpUserWithoutToken(data) {
        let promise = super.postWithoutToken({
            url: SAVE_USERINFO,
            data: data,
        });
        return proxy.httpResultProxy(promise, UserModelProxy);
    }

    // 修改密码 PUT /users/password/{username}
    putPassword(data) {
        let promise = super.put({
            url: SAVE_USERINFO + `/${data.username}/password`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, SimpleHttpRequestProxy);
    }

    // 修改邮箱 PUT /users/email/{username}
    putEditEmail(data) {
        let promise = super.put({
            url: SAVE_USERINFO + `/${data.username}/email`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, SimpleHttpRequestProxy);
    }

    // 查询
    getUsersByQuery = (data) => {
        let promise = super.post({
            url: SAVE_USERINFO + '/search',
            params: data.params,
            headers: {
                'Content-Type': 'application/json',
            },
        });
        return proxy.httpResultProxy(promise);
    };

    getMutiplyUserInfo = (userAyyay) => {
        let promise = super.post({
            url: SAVE_USERINFO + '/search?matchType=2',
            data: userAyyay,
        });
        return proxy.httpResultProxy(promise);
    };

    // POST /users/{userId}/sendResetPwdLinkEmail 发送重置密码链接到邮箱
    senResetPwdLinkEmail = (data) => {
        let promise = super.postWithoutToken({
            url: `${SAVE_USERINFO}/${data.id}/sendResetPwdLinkEmail`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // POST /users/verifyResetPwdSignature 检测重置密码的签证是否正确
    isWithSignature = (data) => {
        let promise = super.postWithoutToken({
            url: `${SAVE_USERINFO}/verifyResetPwdSignature`,
            data,
        });
        return proxy.httpResultProxy(promise);
    };
    // PUT /users/password/signature 根据签证重置密码
    resetUserPwd = (data) => {
        let promise = super.putWithoutToken({
            url: `${SAVE_USERINFO}/password/signature`,
            data,
        });
        return proxy.httpResultProxy(promise);
    };
    // POST /users/{userId}/resumes  创建一个履历
    createdResumes = (data) => {
        let promise = super.post({
            url: `${SAVE_USERINFO}/${data.username}/resumes`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, UserResumesModelProxy);
    };
    // DELETE /users/{userId}/resumes/{resumeId}  修改一个履历
    deleteResumes = (data) => {
        let promise = super.delete({
            url: `${SAVE_USERINFO}/${data.username}/resumes/${data.resumeId}`,
        });
        return proxy.httpResultProxy(promise, UserResumesModelProxy);
    };
    // PUT /users/{userId}/resumes/{resumeId}  修改一个履历
    editResumes = (data) => {
        let promise = super.put({
            url: `${SAVE_USERINFO}/${data.username}/resumes/${data.resumeId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, UserResumesModelProxy);
    };
    // PUT /users/{userId}/bind  绑定接口
    bindByCode = (data) => {
        let promise = super.put({
            url: `${SAVE_USERINFO}/${data.username}/bind`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, UserResumesModelProxy);
    };
    // 我的推广信息
    getMyInviteInfo = (data) => {
        let promise = super.get({
            url: `/stats${SAVE_USERINFO}/${data.userId}/inviteinfo?withInviteAmount=false`,
        });
        return proxy.httpResultProxy(promise, UserModelProxy);
    };
    // 检查用户是否存在
    checkExist = (data) => {
        let promise = super.getWithoutToken({
            url: `${SAVE_USERINFO}/checkExist`,
            params: data,
        });
        return proxy.httpResultProxy(promise, UserModelProxy);
    };
}

export {UserService};
